if exists (select 1
          from sysobjects
          where  id = object_id('bd_proc_schedule_ge_ren')
          and type in ('P','PC'))
   drop procedure bd_proc_schedule_ge_ren
go


create procedure bd_proc_schedule_ge_ren (@user_serial_str varchar(max),@ban_ci_ge_ren varchar(max),@rest_day varchar(max),@record_type int,@most_work_day int,@one_in_full_attendance int,@zero_in_full_attendance int,@compute_over_time int,@compute_leave int,@festival int,@ip varchar(max),@operator varchar(max)) as
BEGIN
/*
@one_in_full_attendance+@record_type+@compute_leave
kq_rule： 'a,b,c,d,e,f,g,h'

a 代表最多上班天数 输入框
b 每周固定休息日 选择框
c 计算加班 复选框
d 考勤一次满考勤 复选框
e 工作日无有效考勤记录时记(休息 旷工) 选择框
f 计算请假 复选框
g 不考勤也算满勤 复选框
h 节假日有效 复选框

*/

-- 关闭打印受影响行数
SET NOCOUNT ON;


-- 定义返回受影响行数结果
	declare @result int = 0;


	--  异常扑捉机制
		BEGIN TRY

			CREATE TABLE #user_serial(
				id INT IDENTITY,
				user_serial VARCHAR(20)
			)


		-- 开启事务
			BEGIN TRAN


				-- 拆分用户编号保存临时表中
				insert into #user_serial
				select * from string_split(iif(isnull(@user_serial_str,'')='','',@user_serial_str),',');

				
				update du set du.kq_taoban=@user_serial_str,du.kq_rule= @most_work_day+@rest_day+@compute_over_time+@one_in_full_attendance+@record_type+@compute_leave+@zero_in_full_attendance+@festival
				from dt_user du
				inner join #user_serial us on du.user_serial = us.user_serial
				where (du.dep_no is not null) and (du.user_type<=50)


				set @result = @result + @@ROWCOUNT;


		--  提交事务
			COMMIT TRAN

	--  结束异常捕捉
		END TRY

	--  异常处理
		BEGIN CATCH
			DECLARE @errStr VARCHAR(MAX) = ERROR_MESSAGE();
			IF XACT_STATE() <> 0
			BEGIN
			  ROLLBACK TRANSACTION;
			  RAISERROR (@errStr, 16, 1);
			END;
			ROLLBACK TRAN;
		END CATCH



--  清除临时表
	DROP TABLE #user_serial

	select @result as result


-- 打开打印受影响行数
SET NOCOUNT OFF;
END;
go
